package com.jprocms.module.cms.api;

import cn.hutool.core.lang.Assert;
import com.jpro.framework.common.pojo.CommonResult;
import com.jprocms.module.cms.api.dto.SiteConfigDto;
import com.jprocms.module.cms.dal.dataobject.site.SiteDO;
import com.jprocms.module.cms.service.site.SiteService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

import static com.jpro.framework.common.exception.util.ServiceExceptionUtil.exception;
import static com.jpro.framework.common.pojo.CommonResult.success;
import static com.jprocms.module.cms.enums.ErrorCodeConstants.SITE_NOT_EXISTS;

@RestController // 提供 RESTful API 接口，给 Feign 调用

@Validated
public class SiteConfigApiImpl implements SiteConfigApi {

    @Resource
    private SiteService siteService;

    @Override
    public CommonResult<SiteConfigDto> getSiteConfig(Long id) {
        SiteDO site = siteService.getSite(id);
        Assert.notNull(site, () -> {
            throw exception(SITE_NOT_EXISTS);
        });
        return success(site.getSiteConfig());
    }
}
